#coding=utf-8
'''
Created on 2013年11月6日

@author: xuben
集市商品数据
'''

from ..common import AIConfig, Logger

class MarketGoodsVO:
    
    #编号
    id = 0
    #类型
    itemType = ""
    #数量
    itemNum = 0
    #品质
    quality = 0
    #消耗类型
    costType = ""
    #消耗数量
    costNum = 0
    
    def __init__(self, data):
        '''
        Constructor
        '''
        if 'id' in data:
            self.id = data['id']
        if 'itemType' in data:
            self.itemType = data['itemType']
        if 'itemNum' in data:
            self.itemNum = data['itemNum']
        if 'quality' in data:
            self.quality = data['quality']
        if 'costType' in data:
            self.costType = data['costType']
        if 'costNum' in data:
            self.costNum = data['costNum']
            
    def __cmp__(self, other):
        try:
            typePriority1 = AIConfig.market_goods_priority.index(self.itemType)
            typePriority2 = AIConfig.market_goods_priority.index(other.itemType)
            if typePriority1 < typePriority2:
                return 1
            elif typePriority1 == typePriority2:
                return cmp(self.quality, other.quality)
            elif typePriority1 > typePriority2:
                return -1
        except:
            Logger.log('商品类型错误,type1:'+self.itemType+',type2:'+other.itemType, Logger.LOGGER_ERROR, True)